package com.bicon.botu.mall.component.controller;


import com.baomidou.mybatisplus.plugins.Page;
import com.bicon.botu.mall.component.dto.SearchStatisticsDTO;
import com.bicon.botu.mall.component.entity.SearchStatistics;
import com.bicon.botu.mall.component.mapper.SearchStatisticsMapper;
import com.bicon.botu.core.base.common.controller.BaseController;
import com.bicon.botu.core.base.common.entity.BaseResult;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * 搜索历史统计表 前端控制器
 *
 * @author 张凡
 * @date 2017/8/7 17:07.
 */
@RestController
@CrossOrigin
@Slf4j
@RequestMapping("/V1.0.0/searchStatistics")
public class SearchStatisticsController extends BaseController {
    @Autowired
    SearchStatisticsMapper searchStatisticsMapper;

    /**
     * 获取搜索统计数据
     *
     * @return
     */
    @RequestMapping(value = "/findSearchData", method = RequestMethod.POST)
    public BaseResult findSearchData(@RequestParam String type, @RequestParam Integer pageNo, @RequestParam Integer pageSize) {
        //分页查询
        Page<SearchStatisticsDTO> page = new Page<>(pageNo, pageSize);
        List<SearchStatisticsDTO> searchStatisticsList = searchStatisticsMapper.findSearchData(page, type);
        page.setRecords(searchStatisticsList);
        return sendResult200(page);
    }

    /**
     * 删除统计数据
     *
     * @param id 统计数据id
     * @return
     */
    @RequestMapping(value = "/deleteSearchData", method = RequestMethod.POST)
    public BaseResult deleteSearchData(@RequestParam String id) {
        Boolean result = new SearchStatistics().deleteById(id);
        if (!result) {
            return sendResult(500, "删除统计数据失败");
        }
        return sendResult200();
    }
}
